﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using LearnObjsTableAdapters;

/// <summary>
/// Summary description for LearningObjsBLL
/// </summary>
[System.ComponentModel.DataObject]
public class LearnObjsBLL
{
    ILE_Global ileGlobal = new ILE_Global();

    private LearnObjsTableAdapter _learnobjsAdapter = null;
    protected LearnObjsTableAdapter LearnObjAdapter
    {
        get
        {
            if (_learnobjsAdapter == null)
                _learnobjsAdapter = new LearnObjsTableAdapter();

            return _learnobjsAdapter;
        }
    }

    private RelationsLearnObjStandardTableAdapter _relationsAdapter = null;
    protected RelationsLearnObjStandardTableAdapter RelationsAdapter
    {
        get
        {
            if (_relationsAdapter == null)
                _relationsAdapter = new RelationsLearnObjStandardTableAdapter();

            return _relationsAdapter;
        }
    }

    [System.ComponentModel.DataObjectMethodAttribute
        (System.ComponentModel.DataObjectMethodType.Select, true)]
    public LearnObjs.LearnObjsDataTable GetAllLearnObjs()
    {
        try
        {
            return LearnObjAdapter.GetLearnObjs();
        }
        catch (Exception ex)
        {
            ileGlobal.RecordError("LearnObjsBLL:GetLearnObjs:000 Failed to get LearnObjs", ex, 5);
            return null;
        }
    }

    [System.ComponentModel.DataObjectMethodAttribute
        (System.ComponentModel.DataObjectMethodType.Select, false)]
    public LearnObjs.RelationsLearnObjStandardDataTable GetLearnObjsByStandardID(int standardID)
    {
        try
        {
            return RelationsAdapter.GetRelationsByStandardID(standardID);
        }
        catch (Exception ex)
        {
            ileGlobal.RecordError("LearnObjsBLL:GetLearnObjsByStandardID:000 Failed to get LearnObjs", ex, 5);
            return null;
        }
    }

    [System.ComponentModel.DataObjectMethodAttribute
        (System.ComponentModel.DataObjectMethodType.Select, false)]
    public LearnObjs.RelationsLearnObjStandardDataTable GetLearnObjStandardRelationshipsByLearnObjID(int LearnObjID)
    {
        try
        {
            return RelationsAdapter.GetRelationsByLearnObjID(LearnObjID);
        }
        catch (Exception ex)
        {
            ileGlobal.RecordError("LearnObjsBLL:GetLearnObjStandardRelationshipsByLearnObjID:000 Failed to get data", ex, 1);
            return null;
        }
    }

    [System.ComponentModel.DataObjectMethodAttribute
        (System.ComponentModel.DataObjectMethodType.Select, false)]
    public LearnObjs.LearnObjsRow GetLearnObj(int LearnObjID)
    {
        try
        {
            return LearnObjAdapter.GetLearnObj(LearnObjID)[0];
        }
        catch (Exception ex)
        {
            ileGlobal.RecordError("LearnObjsBLL:GetLearnObj:000 Failed to get a LearnObj. ID:" + LearnObjID.ToString(), ex, 1);
            return null;
        }
    }

    [System.ComponentModel.DataObjectMethodAttribute
        (System.ComponentModel.DataObjectMethodType.Insert, true)]
    public int InsertLearnObj(string title, string link, string directions, string estimatedTime, string learnObjQuizQuestions)
    {
        try
        {
            return Convert.ToInt32(LearnObjAdapter.InsertLearnObj(title, directions, estimatedTime, link, learnObjQuizQuestions, DateTime.Now));
        }
        catch (Exception ex)
        {
            ileGlobal.RecordError("LearnObjsBLL:InsertLearnObj:000 Failed to insert LearnObj", ex, 3);
            return 0;
        }
    }

    [System.ComponentModel.DataObjectMethodAttribute
        (System.ComponentModel.DataObjectMethodType.Update, true)]
    public bool UpdateLearnObj(string title, string link, string estimatedTime, string directions, string learnObjQuizQuestions, int LearnObjID)
    {
        try
        {
            return (LearnObjAdapter.Update(title, directions, estimatedTime, link, learnObjQuizQuestions, DateTime.Now, LearnObjID) == 1);
        }
        catch (Exception ex)
        {
            ileGlobal.RecordError("LearnObjsBLL:UpdateLearnObj:000 Failed to Update LearnObj", ex, 3);
            return false;
        }
    }

    [System.ComponentModel.DataObjectMethodAttribute
        (System.ComponentModel.DataObjectMethodType.Delete, false)]
    public bool DeleteLearnObj(int LearnObjID)
    {
        try
        {
            return (LearnObjAdapter.Delete(LearnObjID) == 1);
        }
        catch (Exception ex)
        {
            ileGlobal.RecordError("LearnObjsBLL:DeleteLearnObj:000 Failed to Delete LearnObj", ex, 3);
            return false;
        }
    }

    [System.ComponentModel.DataObjectMethodAttribute
        (System.ComponentModel.DataObjectMethodType.Insert, false)]
    public bool InsertRelation(int LearnObjID, int standardID)
    {
        try
        {
            return (RelationsAdapter.InsertRelation(LearnObjID, standardID) == 1);
        }
        catch (Exception ex)
        {
            ileGlobal.RecordError("LearnObjsBLL:InsertRelationLearnObjStandard:000 Failed to Insert RelationLearnObjStandard", ex, 3);
            return false;
        }
    }



    [System.ComponentModel.DataObjectMethodAttribute
        (System.ComponentModel.DataObjectMethodType.Delete, false)]
    public bool DeleteRelationByLearnObjID(int LearnObjID)
    {
        try
        {
            return (RelationsAdapter.DeleteRelationByLearnObjID(LearnObjID) >= 0);
        }
        catch (Exception ex)
        {
            ileGlobal.RecordError("LearnObjsBLL:DeleteRelationLearnObjStandardByLearnObjID:000 Failed to Delete RelationLearnObjStandard", ex, 3);
            return false;
        }
    }
}
